home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / hypercrd / xcmds / rtf-redr.hqx / RTFText.c < prev    next >
C/C++ Source or Header  |  1992-12-19  |  2KB  |  86 lines

  1. /*
  2.  * This software is copyright 1992 by Robert Morris.
  3.  * You may freely redistribute this software as shareware
  4.  * if you do so in the same form as you got it. If you find
  5.  * this software useful, please send $12 to:
  6.  *   Robert Morris
  7.  *   P.O. Box 1044
  8.  *   Harvard Square Station
  9.  *   Cambridge, MA 02238
  10.  *   ecognome@aol.com
  11.  * If you incorporate any of this software in any kind of
  12.  * commercial product, please send $2 per copy distributed
  13.  * to the above address.
  14.  */
  15.  
  16. /*
  17.  * RTFText(rtf-text)
  18.  # returns the text from some RTF as a string, ignoring the styling.
  19.  */
  20.  
  21. #include <HyperXCmd.h>
  22. #include <stdlib.h>
  23. #include <ctype.h>
  24. #include "SetUpA4.h"
  25. #include <string.h>
  26. #include "lists.h"
  27. #include "rtf.h"
  28.  
  29. Handle HStr(char *);
  30.  
  31. XCmdPtr xptr;
  32. void error(char *);
  33. int goterror;
  34.  
  35. pascal void
  36. main(paramPtr)
  37. XCmdPtr paramPtr;
  38. {
  39.     Handle txt;
  40.     
  41.     RememberA0();
  42.     SetUpA4();
  43.     
  44.     xptr = paramPtr;
  45.     goterror = 0;
  46.     
  47.     if(paramPtr->paramCount != 1){
  48.         error("error : usage RTFText(rtf-text)\rCopyright 1992 by Robert Morris.");
  49.         goto out;
  50.     }
  51.     
  52.     parsertf(paramPtr->params[0], (MyStyleHandle *) 0, &txt);
  53.  
  54.     if(goterror)
  55.         goto out;
  56.     
  57.     paramPtr->returnValue = txt;
  58.     txt = 0;
  59.  
  60. out:
  61.     if(goterror && paramPtr->returnValue == 0)
  62.         paramPtr->returnValue = HStr("error : out of memory!");
  63.     RestoreA4();
  64. }
  65.  
  66. Handle
  67. HStr(str)
  68. char *str;
  69. {
  70.     Handle newHndl;
  71.     
  72.     newHndl = (Handle) NewHandle((long) strlen(str) + 1);
  73.     if(newHndl == 0)
  74.         return(0);
  75.     strcpy((char *) (*newHndl), str);
  76.     return(newHndl);
  77. }
  78.  
  79. void
  80. error(s)
  81. char *s;
  82. {
  83.     if(goterror == 0)
  84.         xptr->returnValue = HStr(s);
  85.     goterror = 1;
  86. }